package com.xt.purchasingsystem.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xt.purchasingsystem.dto.BuyerExecuteDto;
import com.xt.purchasingsystem.model.BuyerExecute;
import com.xt.purchasingsystem.model.BuyerExecuteDetail;
import com.xt.purchasingsystem.service.BuyerExecuteDetailService;
import com.xt.purchasingsystem.service.BuyerExecuteService;
import com.xt.purchasingsystem.utils.Result;
import com.xt.purchasingsystem.utils.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yhp
 * @since 2020-05-31
 */
@RestController
@RequestMapping("/buyerExecuteDetail")
public class BuyerExecuteDetailController {
    @Autowired
    private BuyerExecuteDetailService buyerExecuteDetailService;
@Autowired
private BuyerExecuteService buyerExecuteService;
    /**
     * 根据执行单编号和供应商编号查询对应的执行单明细
     * @param buyerExecuteId
     * @param supplierId
     * @return
     */
    @GetMapping("/{buyerExecuteId}/{supplierId}")
    public Result getAllBuyerExecuteDetailByBuyerExecuteIdAndSupplierId(@PathVariable String buyerExecuteId, @PathVariable String supplierId) {
        QueryWrapper<BuyerExecuteDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("BUYER_EXECUTE_ID",buyerExecuteId).eq("supplier_id",supplierId).eq("register_tag","R001-0");
        List<BuyerExecuteDetail> buyerExecuteDetails = buyerExecuteDetailService.list(queryWrapper);

        BuyerExecute buyerExecute = buyerExecuteService.getById(buyerExecuteId);

        BuyerExecuteDto buyerExecuteDto=new BuyerExecuteDto();
        buyerExecuteDto.setBuyerExecute(buyerExecute);
        buyerExecuteDto.setBuyerExecuteDetails(buyerExecuteDetails);
        return ResultFactory.buildSuccessResult("查询成功",buyerExecuteDto);
    }


}

